/**
 * Copyright (C), 2001-2023, www.bosssof.com.cn
 * FileName: AbstractService
 * Author: Administrator
 * Date: 2023-04-06 18:16:39
 * Description:
 * <p>
 * History:
 * <author> Administrator
 * <time> 2023-04-06 18:16:39
 * <version> 1.0.0
 * <desc> 版本描述
 */
package com.bosssoft.usercenter.service;

import com.bosssoft.usercenter.base.BaseEntity;
import com.bosssoft.usercenter.constant.GlobalConstant;

import java.util.Date;

/**
 * @ClassName: AbstractService
 * @Description: 类的主要功能描述
 * @Author: Administrator
 * @Date: 2023-04-06 18:16
 **/
public abstract class AbstractService {
    /**
     * 标记操作类型
     */
    public enum OperateType{
        /**
         * 增加
          */
        ADD,
        /**
         * 修改
         */
        UPDATE
    }

    /**
     *  对通用字段赋值
     * @param baseEntity 源字段
     * @param operateType 操作类型 是 ADD  或者 UPDATE
     */
    protected void initCommonField(BaseEntity baseEntity,OperateType operateType){
        if(operateType==OperateType.ADD){
            if(baseEntity.getCreatedBy()==null){
                baseEntity.setCreatedBy(GlobalConstant.DEFAULT_CREATOR_ID);
                baseEntity.setUpdatedBy(GlobalConstant.DEFAULT_MODIFIOR_ID);
            }
            if(baseEntity.getCreatedTime()==null){
                baseEntity.setCreatedTime(new Date());
                baseEntity.setUpdatedTime(new Date());
            }

        }
    }
}
